package pl.edu.agh.pros.proxy.view;

import pl.edu.agh.pros.proxy.model.ProviderInfo;
import pl.edu.agh.pros.proxy.view.info.GeneralInfoForm;
import pl.edu.agh.pros.proxy.view.key.AppKeysLayout;
import pl.edu.agh.pros.proxy.view.xmpp.XmppServersLayout;

import com.vaadin.terminal.ThemeResource;
import com.vaadin.ui.Layout;
import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.Tab;
import com.vaadin.ui.VerticalLayout;

public class TabSheetLayout extends VerticalLayout implements TabSheet.SelectedTabChangeListener {

	private static final String COMMON_HEIGHT = "40em";

	private static final long serialVersionUID = 3017036057830985601L;

	// Icons for the table
	private static final ThemeResource icon1 = new ThemeResource("icons/32/settings.png");
	private static final ThemeResource icon2 = new ThemeResource("icons/32/lock.png");
	private static final ThemeResource icon3 = new ThemeResource("icons/32/globe.png");

	private TabSheet t;

	public TabSheetLayout(ProviderInfo providerInfo) {
		// Tab 1 content
		Layout l1 = new VerticalLayout();
		l1.setHeight(COMMON_HEIGHT);
		l1.setMargin(true);
		l1.addComponent(new GeneralInfoForm(providerInfo));
		// Tab 3 content
		XmppServersLayout l3 = new XmppServersLayout(providerInfo.getKey());
		l3.setHeight(COMMON_HEIGHT);
		l3.setMargin(true);

		// Tab 2 content
		VerticalLayout l2 = new AppKeysLayout(providerInfo.getKey(), l3.getTable());
		l2.setHeight(COMMON_HEIGHT);
		l2.setMargin(true);

		t = new TabSheet();

		t.addTab(l1, "General Info", icon1);
		t.addTab(l2, "Application Configurations", icon2);
		t.addTab(l3, "XMPP Servers", icon3);
		t.addListener(this);

		addComponent(t);
	}

	public void selectedTabChange(SelectedTabChangeEvent event) {
		TabSheet tabsheet = event.getTabSheet();
		Tab tab = tabsheet.getTab(tabsheet.getSelectedTab());
		if (tab != null) {
			getWindow().showNotification("Selected tab: " + tab.getCaption());
		}
	}
}